package com.dragon.codefx.dataBase.service.impl;

import com.dragon.codefx.dataBase.controller.dto.DatabaseAddDTO;
import com.dragon.codefx.dataBase.dao.DatabaseConfigDao;
import com.dragon.codefx.dataBase.entity.DatabaseConfigEntity;
import com.dragon.codefx.dataBase.service.DatabaseConfigService;
import com.dragon.common.JpaServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * 数据库配置 业务接口实现类
 *
 * @author lsc
 * @version V1.0
 * @date 2025-6-20
 */
@Slf4j
@Service
public class DatabaseConfigServiceImpl extends JpaServiceImpl<DatabaseConfigDao, DatabaseConfigEntity, Integer> implements DatabaseConfigService {

    @Override
    public DatabaseConfigEntity findById(Integer id) {
        Optional<DatabaseConfigEntity> optional = getJpaDao().findById(id);
        return optional.orElse(null);
    }

    @Override
    public boolean verify(DatabaseAddDTO databaseAddDTO) {
        DatabaseConfigEntity entity =getJpaDao().findOneByUrlAndPort(databaseAddDTO.getUrl(), databaseAddDTO.getPort());
        return ObjectUtils.isNotEmpty(entity);
    }

    @Override
    public void removeByIds(List<Integer> idList) {
        getJpaDao().deleteByIdList(idList);
    }
}